import axios from 'axios'
// 将data:{phone,pwd}  转化为"phone"+phone+"&pwd"+pwd
import qs from 'qs'
// 跨域时json格式和x-www-form-urlencoded转换
const headers={
    // 'Content-Type':'application/x-www-form-urlencoded'
}
const prefix="/users"
const prefix1="/students"

export const getPhone =async(phone)=>{
let response= await axios({
     headers,
     method:"post",
     url:prefix+"/findby",
     data:
    qs.stringify({phone})  
 })
   return response.data;
}
export const addLo =async(phone,pwd)=>{
  let response= await axios({
       headers,
       method:"post",
       url:prefix+"/register",
       data:
      qs.stringify({phone,pwd})  
   })
     return response.data;
  }
  export const login =async(UserDTO={})=>{
    let response= await axios({
        //  headers,
         method:"post",
         url:prefix+"/login",
         data:UserDTO
     })
       return response.data;
    }
    export const add =async(data)=>{
      let response= await axios({
        // headers,
        method:"post",
        url:prefix1,
        data:data
      })
       return response.data
  }
  export const del =async(id)=>{
   // 如果为get ,参数放在params属性中，并且不需要转换
 let response= await axios({
      headers,
      method:"delete",
      url:prefix1+"/"+id,

  })
    return response;
 }
 export const update =async(data)=>{
   // 如果为get ,参数放在params属性中，并且不需要转换
 let response= await axios({
      
      method:"put",
      url:prefix1,
      data:data
  })
    return response;
 }
 export const showStuById =async(id)=>{
   // 如果为get ,参数放在params属性中，并且不需要转换
   console.log(id)
 let response= await axios({
      // headers,
      method:"get",
      url:prefix1+"//findById",
      data:id 
  })
    //  console.log(response.data);
    return response.data;
 }
 export const getSession =async()=>{
let response= await axios({
     method:"get",
     url:"/getSession", 
 })
   return response.data;
}
export const setSession =async()=>{
let response= await axios({
     method:"get",
     url:"/removeSession", 
 })
   return response.data;
}
    export const findAll =async(pageParm={})=>{
      let response= await axios({
        //  headers,
         method:"get",
         url:prefix1+"/findAll",
         params:pageParm
       })
      //  console.log(response.data);
       return response.data;

    }
